package com.bw.shop

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.bumptech.glide.Glide
import com.bw.shop.databinding.ActivityXqactivityBinding
import com.bw.shop.entity.CartEntity
import com.bw.shop.room.DataUtils
import com.therouter.TheRouter
import com.youth.banner.Banner
import com.youth.banner.loader.ImageLoader
import kotlin.math.log

class XQActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding= ActivityXqactivityBinding.inflate(layoutInflater)
        setContentView(binding.root)






        binding.addcart.setOnClickListener {

            Log.d("123", "onCreate: ")

            val queryAll = DataUtils.GetCartDB().GetCartDao().queryAll()
            var  count= queryAll.size+1
            DataUtils.GetCartDB().GetCartDao().insert(CartEntity(1,"通用雨披车衣niulife现货包邮","19.00",count,false,"风雨无阻 助力骑行"))

        }

        binding.tocart.setOnClickListener {

            TheRouter.build("/Shop/CartActivity").navigation()

        }

        val BannerList: ArrayList<String> = arrayListOf()


        BannerList.add("https://developer.huawei.com/allianceCmsResource/resource/HUAWEI_Developer_VUE/images/homeNew/banner4-1124.jpg")
        BannerList.add("http://10.161.9.80:7015/banner/banner4.png")
        BannerList.add("http://10.161.9.80:7015/banner/banner6.png")


       val banner= findViewById<Banner>(R.id.banner)

        banner.apply {
            setImages(BannerList)
            setImageLoader(object : ImageLoader() {
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    if (context != null && path != null) {
                        Glide.with(this@XQActivity).load(path as String).into(imageView!!)
                    }
                }
            })
            isAutoPlay(true)  // 开启自动轮播
            // 轮播间隔3秒
            start()
        }

    }
}